package com.guigu.qingcheng.servicegoods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.qingcheng.pojo.goods.TbAlbum;
import com.guigu.qingcheng.servicegoods.mapper.TbAlbumMapper;
import com.guigu.qingcheng.servicegoods.service.TbAlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@Service
public class TbAlbumServiceImpl extends ServiceImpl<TbAlbumMapper, TbAlbum> implements TbAlbumService {

    @Resource
    private TbAlbumMapper mapper;

    @Autowired
    private TbAlbumService tbAlbumService;

    //根据条件查询封装查询对象
    public QueryWrapper<TbAlbum> queryWrapper(Map<String, Object> searchMap){
        QueryWrapper<TbAlbum> wapper = new QueryWrapper<TbAlbum>();
        if(searchMap != null){
            if(searchMap.get("id") != null && !"".equals(searchMap.get("id")))
                wapper.eq("id", searchMap.get("id"));
            if(searchMap.get("title") != null && !"".equals(searchMap.get("title")))
                wapper.like("title", searchMap.get("title"));
        }
        return wapper;
    }

    @Override
    public Page<TbAlbum> findPage(Map<String, Object> searchMap, int page, int size) {
        Page<TbAlbum> pageAlbum = new Page<TbAlbum>(page, size);
        QueryWrapper<TbAlbum> query = queryWrapper(searchMap);
        IPage<TbAlbum> list = this.tbAlbumService.page(pageAlbum, query);
        return pageAlbum;
    }

    @Override
    public List<TbAlbum> findList(Map<String, Object> searchMap) {
        QueryWrapper<TbAlbum> wrapper = queryWrapper(searchMap);
        List<TbAlbum> list = this.tbAlbumService.list(wrapper);
        return list;
    }
}
